﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Xml.Linq;
using Acando.Dynamics.CRM.Silverlight.Library.Helper;
//using Acando.Dynamics.CRM.Silverlight.Library.CrmProxyWcf;
//using Acando.Dynamics.CRM.Silverlight.Library.CrmSdk;
using Acando.Dynamics.CRM.Silverlight.Library.MetaSdk;
using Acando.Dynamics.CRM.Silverlight.Library.Interfaces;

namespace Acando.Dynamics.CRM.Silverlight.Library.Controls.FieldControls
{
    /// <summary>
    /// Interaction logic for CrmFieldControl.xaml
    /// </summary>
    public partial class CrmFieldControl : UserControl
    {
        public CrmFieldControl()
        {
            InitializeComponent();
        }

        public CrmFieldControl(IRecordControl mainControl, EntityMetadata metadata, XElement cellDefinition)
            : this()
        {
            this.Width = 400;
            this.lblAttribute.Text = (from lbl in cellDefinition.Elements("labels").Elements("label") 
                                      where lbl.Attribute("languagecode").Value == ApplicationContext.Current.GetUserLanguage().ToString() 
                                      select lbl.Attribute("description").Value).First();
            if (cellDefinition.Elements("control").Count() > 0)
                this.pnlValueControl.Children.Add(ValueControlFactory.CreateControl(mainControl, metadata, cellDefinition));
        }
    }
}
